class Solution:
    def wonderfulSubstrings(self, word: str) -> int:
        counter = [0 for _ in range(1024)]
        counter[0] = 1
        mask = 0
        res = 0
        for i in range(len(word)):
            sc = ord(word[i]) - ord('a')
            mask ^= (1 << sc)
            res += counter[mask]
            counter[mask] += 1
            for j in range(10):
                res += counter[mask ^ (1 << j)]

        return res


if __name__ == '__main__':
    print(Solution().wonderfulSubstrings('aba'))
    print(Solution().wonderfulSubstrings('aabb'))
    print(Solution().wonderfulSubstrings('he'))
